Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add add_similar_to_expression! for arrays #798

Merged
merged 6 commits into from
Dec 4, 2024

Conversation

lbonaldo
Copy link
Collaborator

@lbonaldo lbonaldo commented Nov 25, 2024

Description

Addresses #778 by adding a new version of add_similar_to_expression! in expression_manipulation.jl, which handles expressions that are Arrays rather than GenericAffExpr. This implementation performs an elementwise sum of the two arrays, similar to the behavior of the + operator in EP[:expr1] = EP[:expr1] + EP[:expr2] when expr* are vectors.

What type of PR is this? (check all applicable)

  • Bug Fix

Related Tickets & Documents

#778.

Checklist

  • Code changes are sufficiently documented; i.e. new functions contain docstrings and .md files under /docs/src have been updated if necessary.
  • The latest changes on the target branch have been incorporated, so that any conflicts are taken care of before merging. This can be accomplished either by merging in the target branch (e.g. 'git merge develop') or by rebasing on top of the target branch (e.g. 'git rebase develop'). Please do not hesitate to reach out to the GenX development team if you need help with this.
  • Code has been tested to ensure all functionality works as intended.
  • CHANGELOG.md has been updated (if this is a 'notable' change).
  • I consent to the release of this PR's code under the GNU General Public license.

How this can be tested

As the Issue description suggests, this can be replicated with the 5_three_zones_w_piecewise_fuel example case by entering 2000 for the Static_Contingency_MW.

Post-approval checklist for GenX core developers

After the PR is approved

  • Check that the latest changes on the target branch are incorporated, either via merge or rebase
  • Remember to squash and merge if incorporating into develop

@lbonaldo lbonaldo added the bug Something isn't working label Nov 25, 2024
Copy link
Collaborator

@RuaridhMacd RuaridhMacd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks good to me.

Using eachindex seems to work just as well as broadcasting or map!.

In my tests, using map!(+,arr1,arr1,arr2) was slightly faster but it's negligible and I think the loop is fine.

@lbonaldo lbonaldo added this to the v0.4.2 milestone Dec 4, 2024
lbonaldo and others added 5 commits December 4, 2024 11:32
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@lbonaldo lbonaldo force-pushed the 778-bug-no-method-matching-add_to_expression branch from 166b7af to de84382 Compare December 4, 2024 16:33
@lbonaldo
Copy link
Collaborator Author

lbonaldo commented Dec 4, 2024

Thank you @RuaridhMacd, for testing and approving it! I’ll keep that in mind for future optimizations if needed.

@lbonaldo lbonaldo merged commit 165836d into develop Dec 4, 2024
9 checks passed
@lbonaldo lbonaldo deleted the 778-bug-no-method-matching-add_to_expression branch December 4, 2024 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants